package com.tuanbiao.ui.setting;

import android.content.Context;
import android.content.Intent;

import com.hzjq.data.entity.BlastLonLat;
import com.tuanbiao.base.mvp.BasePresenterActivity;
import com.tuanbiao.controllers.SettingController;
import com.tuanbiao.databinding.ActivitySettingLocationBinding;
import com.tuanbiao.models.SettingModel;
import com.tuanbiao.presenter.setting.SettingLocationPresenter;

public class SettingLocationActivity extends BasePresenterActivity<SettingLocationPresenter, ActivitySettingLocationBinding> implements SettingController.LocationView {

    public static void start(Context context) {
        Intent starter = new Intent(context, SettingLocationActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected SettingLocationPresenter createPresenter() {
        return new SettingLocationPresenter(new SettingModel(), this);
    }

    @Override
    protected ActivitySettingLocationBinding getBindingView() {
        return ActivitySettingLocationBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        binding.ivToolbarBack.setOnClickListener(getBackListener());
        binding.btnSave.setOnClickListener(view -> {
            mPresenter.save(binding.scUseLocation.isChecked(), getString(binding.etLatitude), getString(binding.etLongitude));
        });
    }

    @Override
    public void showDetails(boolean enablePseudoMode, BlastLonLat pseudoLonLat) {
        binding.scUseLocation.setChecked(enablePseudoMode);
        binding.etLatitude.setText(String.valueOf(pseudoLonLat.getLat()));
        binding.etLongitude.setText(String.valueOf(pseudoLonLat.getLon()));
    }
}